import request from '@/axios'
import { SysDictDetailVo, SysDictEditQo, SysDictListVo, SysDictSearchQo } from './types'
import { BaseDeleteQo } from '@/base/api/BaseQo'
import { KeyLabelValueVo } from '@/base/api/KeyLabelValueVo'

export const sysDictPageApi = (data: SysDictSearchQo): Promise<IResponse<Array<SysDictListVo>>> => {
  return request.post({ url: '/sysDict/page.adw', data })
}

export const sysDictDetailApi = (id: number): Promise<IResponse<SysDictDetailVo>> => {
  const data = { id }
  return request.post({
    url: '/sysDict/detail.adw',
    data
  })
}

export const sysDictAddApi = (data: SysDictEditQo): Promise<IResponse<number>> => {
  return request.post({ url: '/sysDict/add.adw', data })
}

export const sysDictUpdateApi = (data: SysDictEditQo): Promise<IResponse<void>> => {
  return request.post({ url: '/sysDict/update.adw', data })
}

export const sysDictDeleteApi = (data: BaseDeleteQo): Promise<IResponse<void>> => {
  return request.post({ url: '/sysDict/delete.adw', data })
}

export const sysDictChooseListApi = (
  codePath: string
): Promise<IResponse<Array<KeyLabelValueVo>>> => {
  const data = { codePath }
  return request.post({ url: '/sysDict/chooseDictList.adw', data })
}

// [[ OnflowGenerator Range (- selectFunctions -) Start ]]
export const selectSysDictCodeListApi = (
  data: SysDictSearchQo
): Promise<IResponse<Array<KeyLabelValueVo>>> => {
  return request.post({ url: '/sysDict/selectCodeList.adw', data })
}
export const selectSysDictNameListApi = (
  data: SysDictSearchQo
): Promise<IResponse<Array<KeyLabelValueVo>>> => {
  return request.post({ url: '/sysDict/selectNameList.adw', data })
}
// [[ OnflowGenerator Range (- selectFunctions -) End ]]

export const refreshSysDictApi = (): Promise<IResponse<void>> => {
  return request.post({ url: '/sysDict/refreshDict.adw' })
}

export const sysDictChildrenListApi = (data: SysDictSearchQo): Promise<IResponse<Array<SysDictListVo>>> => {
  return request.post({ url: '/sysDict/childrenList.adw', data })
}
